﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include <QDialog>
#include <QItemDelegate>
#include "Color.h"
#include "ui_LineStyleDlg.h"
#include <QModelIndex>

class QBoxLayout;
class QTableView;
class QStandardItemModel;

//线样式 combox 代理
class  LineStyleComboxDelegate : public  QItemDelegate
{
    Q_OBJECT

public:
    LineStyleComboxDelegate(QObject *parent = 0) : QItemDelegate(parent) { }
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const  QModelIndex &index)  const;
    void  setEditorData(QWidget *editor, const  QModelIndex &index)  const;
    void  setModelData(QWidget *editor, QAbstractItemModel *model, const  QModelIndex &index)  const;
    void  updateEditorGeometry(QWidget *editor, const  QStyleOptionViewItem &option, const  QModelIndex &index) const;

public:
    void  SetItemTextList(const std::vector<std::wstring>& itemList);

private:
    std::vector<std::wstring> m_itemTextList;
};

//线样式对话框
class LineStyleDlg : public QDialog
{
    Q_OBJECT
public:
    LineStyleDlg(QWidget *parent = nullptr);
    void Init();
    ~LineStyleDlg();

public Q_SLOTS:
    void OnOK();
    void OnCancle();
    void OnCellClicked(const QModelIndex &index);
    void OnClearRepleaseClick();
public:
    double GetLineWidth() const;
    void SetLineWidth(double lineWidth);

    gcmp::Color GetLineColor() const;
    void SetLineColor(const gcmp::Color& color);

    bool GetLineColorOverride() const;
    void SetLineColorOverride(bool isOverride);

    std::wstring GetLineType() const;
    void SetLineType(const std::wstring& lineType);

private:
    void CreateTableView();
    void CreateButton();
    void onMoveRequested(const QPoint& cursorPos, const QPoint& offset);

private:
    Ui::LineStyleDlg m_ui;
    QStandardItemModel* m_pModel;
    double m_lineWindth;
    std::wstring m_lineType;
    gcmp::Color m_lineColor;
    bool m_hasColorOverride;
    std::vector<std::wstring> m_lineTypeList;
    QColor backGroundColor;
};

